<?php
header("content-type:text/html;charset=utf-8");
if (!empty($_POST['webname'])) {
	echo "<hr>";
	echo "****************************************--开始--******************************************";
	echo "<hr>";
}
$html  =  0;
$extArr=$dirArr=array();
//读取所有
function getdir($path){
	global $html,$extArr,$dirArr;
	$baseDirArr=array('a','css','data','dede','image','images','include','install','js','m','plus','special','templets','uploads');
	$arr=scandir($path);
	foreach($arr as $v){
		if($v!="."&&$v!=".."){
			if(is_dir($path."/".$v)){
				if(!(in_array($v, $dirArr))){
					$dirArr[]=$v;
				}
				getdir($path."/".$v);
			}else{
				$ext = substr($v, (strrpos($v, ".") + 1));
				if(!(in_array($ext, $extArr))){
					$extArr[]=$ext;
				}
				$path_b=trim($path,'m/');
				if ($ext == 'html') {
					$baseDir=substr($path_b,0,strpos($path_b, '/'));
					if(!(in_array($baseDir, $baseDirArr))){
						$html++;
						echo "http://m.benet-wh.com.cn/" . $path_b . "/" . $v."<br>";
					}
				}
			}
		}
	}
}
$dirname = $_POST['webname'];
if (!empty($_POST['webname'])) {
	echo $dirname;
	echo "<hr>";
	getdir($dirname);

	echo "<hr><hr>";
	echo "递归".$dirname . "</br>";
	echo "<br>";
	echo "遍历的HTML文件" . $html . "个!";
	echo "<hr>";
	sort($extArr);
	sort($dirArr);
	echo $dirname."里有以下文件夹：";
	echo "<pre>";
//	print_r($dirArr);
	echo "</pre>";
	echo "<hr>";
	echo $dirname."里有以下文件：";
	echo "<pre>";
//	print_r($extArr);
	echo "</pre>";
}
if (!empty($_POST['webname'])) {
	echo "<hr>";
	echo "****************************************--结束--******************************************";
	echo "<hr>";
}
?>
<html>
	<head>
		<meta charset="utf-8">
		<title>递归遍历</title>
	</head>
	<body>
		<form action="#" method="post">
			<br />
			<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;输入要递归的文件夹：
			<input type="text" name="webname" id="webname" value="<?php echo $dirname;?>" /> <br />
			<input style="margin-left: 300px;margin-top: 12px;" type="submit" value="开始递归"/>
		</form>
		<br />
		<br />
		<h3>注：输入本程序文件的相对目标文件夹</h3>
		<br />
		<br />
	</body>
</html>